View から ServiceController の HttpPost でメソッドを呼び出しますhttp://localhost/Case/Form
私のserviceControllerクラス:
using System.Web;
using System.Web.Mvc;
[...]
namespace ApnNephro.WebUI.Controllers
{
public class ServicesController : Controller
{
public string GetDomain()
{
string url = "";
try
{
string _url = Request.Url.AbsolutePath;
int _si = (_url.IndexOf("//"));
int _fi = (_url.Substring(_si + 2)).IndexOf("/"); // first /
url = _url.Substring(0, _fi + _si + 2);
return url.ToString();
}
catch (InvalidOperationException ioe)
{
throw new Exception(ioe.Message + " / " + ioe.StackTrace);
}
catch (Exception e)
{
throw new Exception(e.Message + " / " + e.StackTrace);
}
return url.ToString();
}
[...]
そして、私は MailHelper.cs で彼を呼び出します:
private static string domain = new ServicesController().GetDomain();
しかし、 Request が null であるため、例外が発生します...
だから、私の質問は、なぜ Request が null なのですか? 現在のView Controllerでのみ割り当てられているので、ここではCaseControllerのみですか?