0

I have an issue where I am creating a Quartz.NET job (using a copy of Quartz.NET that is embedded in the web application my team is developing, if it matters) that sends an e-mail to certain people containing a hyperlink to a controller/action method that is part of the same application.

To generate this link, I know that some hard coding is unavoidable (due to the lack of there being an actual session created), but I want to use as little hard coding as possible so that it at least has some leeway for change in the event my team eventually wants to reorganize the app architecture. Thankfully, I was able to find a way to manually create a UrlHelper object for the Quartz job to use (see Call UrlHelper in models in ASP.NET MVC).

My issues is that I need some way to manually set the application virtual path stored in the HttpRequest object. This is because the web app is not located at the root of the website we are using.

Do you guys know of any way I can do this? I've tried searching on Google on how to set/change the HttpRequest.ApplicationPath property, or on where the data for that property comes from, but nothing relevant came up.

Community
  • 1
  • 1
user2154603
  • 5
  • 1
  • 4

2 Answers2

0

This is a read only property, as indicated by the documentation, http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx. You can, however do a String.Replace() of the actual root to the new one.

AntLaC
  • 1,215
  • 10
  • 22
  • Where would I do the String.Replace()? Unfortunately, since this is for work, I can't post any actual code without first asking my boss, but the code that creates the UrlHelper is almost verbatim from what J. Pablo Fernández posted in the question I referenced. – user2154603 Jul 05 '13 at 23:28
  • I'm new to .NET programming, so I am still learning the in's and out's of it. – user2154603 Jul 05 '13 at 23:29
  • I apologize for the delay, I've been on vacation. HttpRequest.ApplicationPath returns a string object, so you would attach the replace to it, HttpRequest.ApplicationPath.Replace(). – AntLaC Jul 11 '13 at 14:49
  • Also, FYI, most people are on here for work, just change your code a little so no one can tell where it's from :) You definitely don't want to be posting any proprietary info. But, being able to see a sample of what you're trying to do will help the community help you faster and more accurately – AntLaC Jul 11 '13 at 14:50
  • Thanks on both accounts. That help's a lot. I usually browse solutions here, but this is only my second time actually posting a question. – user2154603 Jul 12 '13 at 15:22
0

As it turns out, the HttpRequest.ApplicationPath property was empty (I guess as the result of manually creating an HttpRequest object), so what I ended up doing was hard-coding the application path in a static field in a Config object and using that instead.

@AntLac: Thanks for your help. Your answer would have worked too.

user2154603
  • 5
  • 1
  • 4