I have created a utility method that contains some try/catches in it. In those try/catches I need to redirect the customer using an HttpResponse redirect. I can’t seem to figure out how to do this outside a web project. This utility class is referenced from my ASP.NET web project and so I’m just abstracting out some of the code into this utility class so I no longer have the request object.
I know I can use HttpWebRequest object for a lot of web related request tasks outside a web project, but could not seem to get any redirect method there to use after putting in a using System.Net; in my utility class.
Top of your file:
In your function:
This way does make your library dependant on the
System.Weblibrary, but your code isn’t in a web project. It will grab the currentHttpContextfor the request it’s called from. You’ll probably want to do some null checking though, if this code is called from outside of a web-context you’re going to get aNullReferenceException.If you’re using WCF there’s a different context-object you want to use, I just can’t remember what it is.
OperationContextmaybe?