简体   繁体   English

在ASP.NET MVC中检查客户数据

[英]Checking customer data in ASP.NET MVC

I am calling a controller action to check the customer serial number before allowing him/her to open a ticket on Zendesk (we need to check if the customer maintenance contract is active). 我正在致电控制器,要求其检查客户序列号,然后再允许他/她在Zendesk上打开工单(我们需要检查客户维护合同是否有效)。 Below you can find the code. 您可以在下面找到代码。

  • How can I open the URL from the controller action? 如何从控制器操作中打开URL?
  • What ActionResult do I need to return afterward? 之后我需要返回什么ActionResult

Thanks. 谢谢。

public ActionResult OpenTicket(string serialNumber, string version)
{
   if (customerSubscription.IsExpired == false)           
   {
       // need to open this URL
       // https://devdept.zendesk.com/tickets/new?ticket[fields[111111]]=" + serialNumber + "&ticket[fields[222222]]=" + version);
   }
   else
   {
       // display an error page with upsell options
   }   

}

To redirect to some url you could use the Redirect method from base controller. 要重定向到某些网址,您可以使用基本控制器中的Redirect方法。 To return some errors to a View, you could add the error on the ModelState and send it to View. 要向视图返回一些错误,您可以在ModelState上添加错误并将其发送给View。 Look the code bellow with the comments: 在下面的代码中添加注释:

public ActionResult OpenTicket(string serialNumber, string version)
{
   if (!customerSubscription.IsExpired)           
   {
       // use the Redirect method from base controller
       return Redirect("https://devdept.zendesk.com/tickets/new?ticket[fields[111111]]=" + serialNumber + "&ticket[fields[222222]]=" + version);
   }
   else
   {
       // display an error page with upsell options
       ModelState.AddModelError("ErrorKey", "Custom error message");
       // it will return OpenTicket view, otr pass a name you want to return
       return View(); 

       // if you redirect here, you will lose the ModelState.
   }   
}

in your view, you could: 您认为,您可以:

@Html.ValidationSummary()

You have 2 options depending on where you want to put the external service call. 您有2个选项,具体取决于您要拨打外部服务呼叫的位置。

  1. The server detects an expiration and informs the user to refresh their subscription. 服务器检测到到期并通知用户刷新其订阅。 The user then goes to the external service URL, refreshes subscription and manually returns back to your site. 然后,用户转到外部服务URL,刷新订阅并手动返回到您的站点。

  2. The server detects an expiration, automatically call the external service to refresh user's subscription and perform consequent business logic having user subscription active. 服务器检测到到期, 自动调用外部服务以刷新用户的订阅, 并执行随后激活用户订阅的业务逻辑 The user is provisioned with ActionResult and interact further on. 向用户提供ActionResult并进一步进行交互。

CASE 1: Use Redirect and provide external service URL 案例1:使用重定向并提供外部服务URL

return Redirect(urlString)

CASE 2: Use external service call within: 1. your controller or 2. delegate to business_logic/service tier. 情况2:在以下范围内使用外部服务调用:1.您的控制器或2.委托给business_logic / service层。 In the case of SOAP communication, add a service reference or generate a proxy using svcutil.exe, otherwise you may use HttpWebRequest ( See ). 对于SOAP通信,请使用svcutil.exe添加服务引用或生成代理,否则,您可以使用HttpWebRequest请参阅参考资料 )。 To gain performance you can consider asynchronous approach for not to block a thread allocated to serve incoming requests. 为了获得性能,您可以考虑采用异步方法 ,即不阻塞分配用于处理传入请求的线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM