开发者

help resolve url in facade class or controller class

开发者 https://www.devze.com 2022-12-18 13:33 出处:网络
I have a facade class that my controller class calls out to and in that facade class, for whatever reason, I\'m building a string a href element.

I have a facade class that my controller class calls out to and in that facade class, for whatever reason, I'm building a string a href element.

And it resolves fine in casini but when it gets out in the real开发者_如何学编程 world like localhost it doesn't work. Is there a way to do this?

string goBackLinkForErrorMessage = "<br /><a href='/MyController/Action?id=" + blah + "'>Go Back</a>";

Thanks, Rod.


I assume this is in a directory that is not the root? The / at the beginning of your URL is going to take the link to the root of the site. I would assume you need to put some logic at the front of the URL to build it correctly.

So something like this:

string goBackLinkForErrorMessage = "<br /><a href=" + Request.ApplicationPath.TrimEnd('/') + "'/MyController/Action?id=" + blah + "'>Go Back</a>";

You will want to keep the TrimEnd on the end of that Application Path for cases when it is the root.

A lot of this was made on assumptions because "it doesn't work" isn't real clear.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号