ASP Classic can I use Response.AppendToLog in global.asa Application_onStart - asp-classic

In ASP Classic can i use Response.AppendToLog in global.asa Application_onStart ?
I would try to Log error when application starts, but i always get this error:
erreur '8002802b'
/v1/common/CAppInit.asp, line 21
line 21:
Response.AppendToLog "INIT DB ERROR"

You can’t use the Response object in the global.asa file because there is no context for a response. The global.asa file deals with Application and Session level context.
If you think about it, when the application starts there doesn’t need to be a response because there is no initial request, it operates entirely outside of that pipeline.
The definition of the Response.AppendToLog() method is as follows;
The AppendToLog method adds a string to the end of the Web server log entry for the request.
This means that an initial request is required, which makes using it in the context of application startup impossible.
The usual solution is to implement a custom logging function that can be utilised inside the context of the Application or Session startup events.

Related

Owin.Security.OAuth don't fire ValidateClientRedirectUri

I made a web .net application in C#. I started from the ASP.NET Web application (.NET Framework) template project in Visual Studio.
I added the Owin.Security.OAuth library and I implemented the service provider in my code.
When I run the application with IIS Express it works well. When I try to run the application in the remote IIS server, when I try the login it fails on the authorization phase.
The application got 2 areas (AMSCetra and GestDrivMe) with their controllers and views, and a HomeController (the project default controller) with an Index api method that redirect to the specific areas index.
I tried to debug the difference between local and remote behaviour.
When i work in local IIS Express, the chain of requests to my application is a little different:
call Login method of my AccountController, that redirect to "/" after the account authentication and after getting roles
call OnAuthorization method of my AuthorizeAttribute (the AuthorizationContext's controller's request point to the area's file /AMScetra/AMSCetra)
call AuthorizeCore method of my AuthorizeAttribute (HttpContextBase parameter's request is for the same location of the point 2) and the user is Authenticated and "InRole"
call the specific area's controller Index api method (AMSCetraController.Index)
invoke the ValidateClientRedirectUri method of my AuthProvider (override of the OAuthAuthorizationServerProvider method). Here calls the context Validated method (the context's request is for the HomeController's Index - "https://localhost:44375/")
call Authorize method of my AccountController, that invoke the AuthenticationManager.SignIn(identity) method and returns an EmptyResult
call the HomeController Index (i don't now why) that redirect to the specific Area Index - "~/AMSCetra/AMSCetra/Index" (seems unuseful but in local it works)
call for a second time OnAuthorization method (request is for "/AMSCetra/AMSCetra/Index" as the previous redirection suggest)
call for a second time AuthorizationCore method (HttpContextBase parameter's request is for the same location of the point 8)
call for a second time the specific area's controller Index api method (AMSCetraController.Index)
I can't understand why the AMSCetraController Index is called two times, or why the application needs to call the HomeController Index after, but I can postpone 'cause it works well (in local IIS Express) and it happen only after the login.
But when I publish on the remote IIS, the calls chain skip point 5 (ValidateClientRedirectUri) and at point 6 (Authorize) the chains end, and a blank page is shown with the uri "http://XXX.XXX.XXX.XXX/Account/Authorize?client_id=web&response_type=token&state=".
I tried to debug the low level Owin library to understand the problem, but I don't know how debug a referenced DLL without PDB files. I tried to understand how the library works on the GitHub source code, but it's not the same.
Seems that is involved the Javascript's Knockout library, and a js method called Sammy, but as before I can't debug that source code, but only my code (indifferently in local or in remote).
I can't understand why IIS Express works well but remote IIS server don't, I already tried to force the MachineKey in my solution and in the remote IIS server, but it doesn't resolve.

Server was unable to process request. in web service method call

Through my project i am making an web service call by adding web reference.
In my project i am creating object like below
PortalService portalService=new PortalService();
if (portalService != null)
{
DataSet ds = portalService.getStateList(3);
}
Its going inside if loop after creating object. But when calling web service method its giving me exception like below
[SoapException: Server was unable to process request. ---> Object reference not set to an instance of an object.]
Why this exception occuring? How do i make web service call?
The code is ok. It looks like there is an exception happening inside the service itself. I would look at the service code, and try to track down the issue. Perhaps the input is not valid?

How to catch AJAX WebMethod errors in global.asax?

I'm using the common practice of catching errors in global.asax in my ASP.net application. In global.asax, I have a function Application_Error that logs the errors to the database.
This works very well to log errors that occur when the user requests a page.
However, this does nothing to help when an asynchronous method (a method decorated with the [WebMethod] attribute) called from the client-side throws an exception. The exception simply bubbles up and may be returned to the client-side code, but I would like to have the error handling code run on the server automatically similar to how page errors are logged in global.asax.
How do I accomplish this? One way would be to wrap every single asynchronous method with try-catch, but this doesn't seem like a good solution to me.
One option is to create an ASP.NET output filter that intercepts and logs WebMethod exceptions sent by ASP.NET to the client. Here's the basic idea:
Create a subclass of Stream that captures the content of the response.
When the stream is closed, check whether the response has a 500 status code as well as a "jsonerror: true" header. If so, the response contains a WebMethod exception; log the exception.
In Global.Application_PostMapRequestHandler, install an instance of this class as the output filter for JSON requests.
For complete source code, see this StackOverflow answer.
How to create a global exception handler for a Web Service

Can I get information about the IIS7 virtual directory from Application_Start?

I have 3 IIS7 virtual directories which point to the same physical directory. Each one has a unique host headers bound to it and each one runs in its own app pool. Ultimately, 3 instances of the same ASP.NET application.
In the Application_Start event handler of global.asax I would like to identify which instance of the application is running (to conditionally execute some code). Since the Request object is not available, I cannot interrogate the current URL so I would like to interrogate the binding information of the current virtual directory?
Since the host header binding is unique for each site, it would allow me to identify which application instance is starting up. Does anyone know how to do this or have a better suggestion?
When a request is made, and just prior to the HttpApplication instance being created, ASP.NET initializes core objects such as HttpContext, HttpRequest and HttpResponse which means they will exist when you get to the Application_Start event in Global.asax. Thus, in Application_Start, you can get the requesting url like so:
var url = this.Context.Request.Url;

"maximum string content length quota (8192) has been exceeded while reading XML data" calling WCF via mexAddress moniker

I'm attempting to call a WCF service via mex from a classic ASP page. I've got the call working using the details on MSDN, but if I pass back an amount of data exceeding 8K I get an exception stating:
The maximum string content length
quota (8192) has been exceeded while
reading XML data. This quota may be
increased by changing the
MaxStringContentLength property on the
XmlDictionaryReaderQuotas object used
when creating the XML reader...
The fix for this is easy enough in .NET client: you can adjust the client config to having a binding with a readerQuotas section including an increased quota. However, since I'm building a service moniker to pass to a GetObject call within ASP, I don't have access to a config to edit. If it were a VB6 app, I could use dllhost.exe.config, but that's not the case. The bindingConfiguration node (and sub nodes) don't appear to be parameters I can set within the moniker string.
Any ideas on how I could influence this parameter within the ASP context? ASP snippet with moniker string referenced below:
Dim strXml, moniker, objProxy
moniker="service:mexAddress='http://localhost/SomeApp/SomeServices/SomeService.svc/mex', "
moniker=moniker + "address='http://localhost/SomeApp/SomeServices/SomeService.svc',"
moniker=moniker + "contract=ISomeService, contractNamespace=http://foo.com, "
moniker=moniker + "binding=WSHttpBinding_ISomeService, bindingNamespace=http://foo.com"
Set objProxy = GetObject(moniker)
strXml = objProxy.DoWork("foo", "bar")
Thanks!
Try setting your maxStringContentLength in your wcf binding configuration on the server side.
It's my understanding that the service:mexAddress moniker actually uses a WCF client behind the COM interface. If that is the case then you can store the WCF config in a file called «foo».exe.config, where «foo» is replaced by the name of the executable.
If you are running the ASP within IIS6 or IIS7, then the EXE that runs the ASP is probably w3wp.exe, which means you need to drop the config into a file called w3wp.exe.config , located in the directory c:\Windows\system32\inetsrv.

Resources