You can always apply wherever you find yourself. But in the EU there is a great chance that the country you apply to will try to use the Dublin regulation to force you to go back to the country that issued your residence permit (it's called a “take charge” request). If that happens, you would still be an asylum seeker and have a shot at refugee status, but in Spain. This system was specifically intended to prevent people in your situation from getting asylum in another EU country than Spain.
Now, the Dublin system has been under a lot of stress recently and, depending on the specifics, that might or might not be possible in practice but it's a risk. By leaving the country for an extended period of time (even if that's to wait to hear whether your asylum application will be processed) and failing to progress in your studies, you might also jeopardise your status as a student so if there is any chance that you could remain a student and transition to another status later on, you might risk that as well by going to Norway.
And Spain/Norway is not a very good combination for your purpose. Spain isn't under pressure to the level that Italy, Hungary or Greece are at the moment, consequently they accept most Dublin requests (unlike Italy) and still receive many (unlike Hungary, because everybody knows asking Hungary is futile, or Greece, because the conditions are so bad that European courts ruled that sending an asylum seeker back there was not acceptable). And while there is much discussion about the future of the Dublin system, I also haven't heard anything suggesting Norway could stop using it while it lasts.