PowerShell is a command line administration tool that comes with Windows. I haven't used it much as a developer, but I have discovered a few little things that make me think it could be useful for discovering what certain .NET objects are capable of without compiling new code.
Check this out:
I created a variable called MyString, and then tested out the SubString function.
Then I wanted to see how the GeneratePassword method of the Membership class worked, so I imported the assembly that contains the Membership class, and called GeneratePassword.
I can see this being useful because I can call .NET code on the fly without first creating a project in Visual Studio.
Tuesday, February 24, 2015
Thursday, February 19, 2015
ASP.NET Web Api 404 errors
I recently deployed a ASP.NET Web Api web service to a production server and kept getting 404 errors when I made requests. After extensive research I finally traced the problem to the web.config file. I don't totally understand why this fixed it, but it has something to do with how IIS resolves the URL.
In the web.config, you'll find this line:
This needs be changed to:
Notice the removal of the period from the "path" attribute.
In the web.config, you'll find this line:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
This needs be changed to:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Notice the removal of the period from the "path" attribute.
Wednesday, February 4, 2015
Response.Redirect
When you redirect to another page using .NET, you normally use the Response.Redirect method. However, if you only supply the URL as the parameter, you'll get a ThreadAbort exception thrown. This can fill the event log pretty darn quick. To avoid this, set the second parameter to False. This will immediately end the response, so no exception is thrown.
The only "exception" to this rule (haha), is when you want code to execute after the Response.Redirect. In this case you can't immediately end the response. In this case, you either have to put up with the exceptions in the log, or catch the ThreadAbort exception and just swallow it.
The only "exception" to this rule (haha), is when you want code to execute after the Response.Redirect. In this case you can't immediately end the response. In this case, you either have to put up with the exceptions in the log, or catch the ThreadAbort exception and just swallow it.
Subscribe to:
Posts (Atom)