标签: model-view-controller

缺少auth0的userInfo中的user_metadata

对于身份验证,我使用的是Auth0 AuthenticationApi.在Account Controller中,我需要获取user_metadata但它已丢失.获取user_metadata的任何替代方法?

AuthenticationApiClient client = new AuthenticationApiClient(new Uri($"https://{_auth0Options.Domain}/"));

               var authenticateResponse = await client.GetTokenAsync(new ResourceOwnerTokenRequest
                {
                    ClientId = _auth0Options.ClientId,
                    ClientSecret = _auth0Options.ClientSecret,
                    Scope = "openid",
                    Realm = _auth0Options.Connection,
                    Username = vm.EmailAddress,
                    Password = vm.Password
                });
                var user = await client.GetUserInfoAsync(authenticateResponse.AccessToken);
                if (user.UserMetadata != null)
                {
        // Giving error...any alternative to access the userMetaData ?
                }
Run Code Online (Sandbox Code Playgroud)

authentication model-view-controller oauth-2.0 auth0

5
推荐指数
1
解决办法
361
查看次数

MVC视频流到移动Web浏览器

嗨,大家好,我想通过ASP.NET MVC Web应用程序将视频从我的Azure blob流式传输到桌面浏览器上的用户,当然还有移动浏览器.

到目前为止我构建的是一个ASP.NET MVC应用程序,它为网站提供服务,而WebApi服务则是PushStreamContent.这在桌面上的Chrome和Edge上非常棒.但是,我试图在移动设备Chrome,Safari,Firefox上打开它,它就不会玩了.

我的代码到目前为止:

关于MVC项目的观点

<video id="vPlayer" class="video-js" autoplay controls playsinline preload="auto" data-setup='{"fluid": true}'poster="@ImgManager.GetVideoImgUrl(Model.ThumbnailUrl)">
<source src="//xyz.nl/api/Videos/Get?filename=340a85a3-ccea-4a2a-bab6-74def07e416c.webm&type=video%2Fwebm" type="video/webm">
<source src="//xyz.nl/api/Videos/Get?filename=340a85a3-ccea-4a2a-bab6-74def07e416c.mp4&type=video%2Fmp4" type="video/mp4">
Run Code Online (Sandbox Code Playgroud)

WebApi

public HttpResponseMessage Get(string filename, string type)
        {
            var video = new VideoStream(filename);
            var response = Request.CreateResponse();

            response.Content = new PushStreamContent(video.WriteToStream, new MediaTypeHeaderValue(type));

            return response;
        }
Run Code Online (Sandbox Code Playgroud)

webAPI上的助手

public class VideoStream
    {
        private readonly string _filename;

        public VideoStream(string fileName)
        {
            _filename = fileName;
        }



        public async Task WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {
                var storage …
Run Code Online (Sandbox Code Playgroud)

c# asp.net model-view-controller video-streaming asp.net-web-api

5
推荐指数
1
解决办法
528
查看次数

调用Abandon()后未清除ASP.net MVC 5会话

MVC菜鸟在这里。

当前,我有以下代码通过AJAX加载页面时会触发HomeController:

namespace ETTData.Controllers
{
  public class HomeController : Controller
  {
    [HttpPost]
    public ContentResult clearSessions()
    {
        var currentSession = System.Web.HttpContext.Current.Session;

        System.Diagnostics.Debug.WriteLine("BEFORE: " + currentSession.Timeout);

        currentSession.Abandon();
        //currentSession.RemoveAll();
        //currentSession.Clear();

        System.Diagnostics.Debug.WriteLine("AFTER : " + currentSession.Timeout);

        return new ContentResult { Content = "OK", ContentType = "text/plain" };
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

debug.WriteLine的输出是:

之前:35

之后:35

所以你可以看到它有35对之前还有35对后,当它不应该等于什么,因为我用currentSession.Abandon(); 在调用该输出之前。

我通过Global.asax.cs文件设置会话超时:

namespace ETTData
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Session_Start(Object sender, EventArgs …
Run Code Online (Sandbox Code Playgroud)

c# asp.net model-view-controller asp.net-mvc asp.net-mvc-5

5
推荐指数
2
解决办法
857
查看次数

CakePHP:控制器或模型中的查询?

如果我真的使用了MVC方法,那么查询应该在模型中,对于CakePHP,查询应该在表类中,但是当我浏览Cake提供的教程和文档时,它们只是声明查询应该在Controller中。

如您在Cake网站上的示例中所见:https : //book.cakephp.org/3.0/en/tutorials-and-examples/blog/part-two.html

但是,如果我通过此链接或遇到了许多其他链接,则查询部分应该在模型中:https : //www.toptal.com/cakephp/most-common-cakephp-mistakes#common-mistake-3-在控制器中保持业务逻辑而不是模型

这不仅与Cake在示例中显示的内容或某些开发人员的意见有关,而且在处理数据库查询时真正应该是在Cake中进行编码的真正方法是什么。我发现几乎90%的人只在Controller中为Cake执行与查询相关的任务,因为他们引用“ Cake在示例中提及的内容相同”。但是关于MVC方式,我们创建表类只是为了提及关联呢?如果Cake自己的网站做到了,那么就意味着他们有意做到了。

php model-view-controller cakephp cakephp-3.0

5
推荐指数
1
解决办法
767
查看次数

Angular 4+ Service引用了另一种服务良好实践

我正在Angular 4.x中编写一个软件,对于该服务处理的每个api请求,都需要知道来自另一个服务(一个ID)的信息。

我的问题是关于角度模式和良好做法。对于我的具体情况,最好的方法是:

1-每次需要使用ID信息进行API请求时,使用服务A调用服务B。像这样:

服务A

@Injectable()
export class AService {

  // ID
  public myId: string;

  [...]
}
Run Code Online (Sandbox Code Playgroud)

服务B

@Injectable()
export class BService {

  constructor(
    private restangular: Restangular,
    private aservice: AService,
  ) { }

  public get(callback: (_: string[]) => void) {
    // Sends the request
    return this.restangular
      .all('myrequest')
      .customGET('', {
        myId: this.aservice.myid,
      })
    [...]
  }

  [...]
}
Run Code Online (Sandbox Code Playgroud)

要么

2-切勿从另一个服务调用服务,并且始终使用组件先调用AService,然后使用BService上的值(这样,每次进行API调用时,都将复制相同的代码(或至少每次调用一次)使用该api调用的组件)。

服务A

@Injectable()
export class AService {

  // ID
  public myId: string;

  [...]
}
Run Code Online (Sandbox Code Playgroud)

服务B

@Injectable()
export class BService {

  constructor(
    private restangular: …
Run Code Online (Sandbox Code Playgroud)

oop model-view-controller components typescript angular

5
推荐指数
1
解决办法
352
查看次数

Angular 4反应形式-显示值

我正在使用反应形式方法。我有一个具有对应的formControl对象的输入字段,并且在键入时我正在对值进行格式化-使所有输入大写。

那当然工作得很好-在视图和formControl中也会更新该值。

The issue is That I would like to send to server the original value and not the formmated value (uppercase)

So I need something like value, and value for display in the formControl object.

See plunker - formatting value formControl

template:

  <input type="text" 
         class="form-control" 
         (blur)="handleOnBlur($event)"
         (input)="onChange($event)"
         formControlName="name">
Run Code Online (Sandbox Code Playgroud)

model:

    valueForModel: string; 
    valueForDisplay: string;
    public myForm: FormGroup;        

 onChange(event) {
    const value = event.target.value;
    this.valueForModel = value;
    this.valueForDisplay = value.toUpperCase();

    event.target.value = this.valueForDisplay;
 }

 handleOnBlur(event) {

   consol.log(this.valueForModel);
    // Herer I'm calling …
Run Code Online (Sandbox Code Playgroud)

model-view-controller model reactive-programming form-control angular

5
推荐指数
1
解决办法
4814
查看次数

View Controller中的依赖注入

我正在尝试使用依赖注入而不是跟随单例。这就是我想要达到的目的。当我运行应用程序时,我在此上出现错误"No "decodeObject" candidates produce the expected contextual result type "ModelManager"。知道如何以正确的方式实现依赖注入吗?

我的模特班:

class ModelManager {
var results: MyCustomClass

init(results: MyCustomClass) {
    self.results = results
}
func update(customDataInfo: MyCustomClass!) {
    self.results = customDataInfo
}
}
Run Code Online (Sandbox Code Playgroud)

MyViewController.swift

class MyViewController: UIViewController {

private let modelManager: ModelManager

init(modelManager: ModelManager) {
    self.modelManager = modelManager
    super.init(nibName: nil, bundle: nil)
    self.modelManager.modelManagerUpdate = self as ModelManagerUpdate
}

 required init?(coder aDecoder: NSCoder) {
    self. modelManager = aDecoder.decodeObject(value(forKey: "modelManager") as ModelManager)
    super.init(coder: aDecoder)

    fatalError("init(coder:) has not been implemented")
} …
Run Code Online (Sandbox Code Playgroud)

model-view-controller singleton dependency-injection swift

5
推荐指数
1
解决办法
1595
查看次数

我想在离开页面之前显示模态弹出窗口

<a href="https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&stacked=h" id="leave">click here to leave the page</a>


<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Changes made may not be saved.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

$("#leave").click(function() {
  $(window).bind('beforeunload', function() {
    return 'Changes you made may not be Saved';
  });
});
Run Code Online (Sandbox Code Playgroud)

这是我工作的小提琴

html javascript css model-view-controller jquery

5
推荐指数
1
解决办法
865
查看次数

当多个URL映射到同一控制器方法时,查找用于访问控制器的URL

我看到Spring MVC将多个url映射到相同的控制器方法

所以现在我有一个方法定义为

@RequestMapping(value = {"/aaa", "/bbb", "/ccc/xxx"}, method = RequestMethod.POST)
public String foo() {
    // was it called from /aaa or /bbb
}
Run Code Online (Sandbox Code Playgroud)

在运行时,我想知道是否从/aaa或调用了控制器/bbb

java model-view-controller spring spring-mvc

5
推荐指数
0
解决办法
55
查看次数

值-1超出[0,2147483647]的可接受范围。参数名称:值

使用Visual Studio 2019脚手架安装任何控制器时出现问题,我收到错误消息:
“运行所选代码生成器时发生错误:'值-1超出[0,2147483647]的可接受范围。参数名:value'”

我尝试过的相关链接仍然仍然存在此问题

我尝试了以下操作:
1.(在Visual Studio 2019中生成视图时出错)
2.(在VS 2015中无法从Controller添加视图:“运行所选代码生成器时出错”)

c# model-view-controller visual-studio visual-studio-2019

5
推荐指数
1
解决办法
1374
查看次数